package Test04;


/**
 * @Author: Re
 * @Date: 2020/12/1 0:10
 */
public class Rectangle {
    float width;
    float length;

    public Rectangle(int width, int length) {
        this.width = width;
        this.length = length;
    }
    public Rectangle(){
        this(10,10);
        this.setWidth(10);
        this.setLength(10);
    }

    public void setLength(float length) {
        if(length>0.0&&length<20.0){
            System.out.println("不合规范");
            return;
        }
        this.length = length;
    }

    public float getLength() {
        return length;
    }

    public void setWidth(float width) {
        if(width>0.0&&width>20.0){
            System.out.println("不合规范");
            return;
        }
        this.width = width;
    }
    public  float  area(){
        return length*width;
    }
    public float perimeter(){
        return (length+width)*2;
    }
    public boolean isSquare(){
        if(width==length) {
            return true;
        }else{
            return false;
        }
    }
    public void compare(Rectangle rectangle){
        if(this.equals(rectangle)){
            System.out.println("相等");
        }else{
            System.out.println("不相等");
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Rectangle rectangle = (Rectangle) o;
        return Float.compare(rectangle.width, width) == 0 &&
                Float.compare(rectangle.length, length) == 0;
    }
}
